package com.blacktry.controller;

import com.blacktry.entity.easypoidata.DeriveExcel;
import com.blacktry.entity.enums.OprLogConst;
import com.blacktry.entity.model.AnswerNumValue;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.service.AutoExamService;
import com.blacktry.utils.ApiResultHandler;
import com.blacktry.utils.log.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(value = "自动评卷管理模块", tags = "自动评卷管理接口")
@RestController
@RequestMapping("/Auto")
public class AutoController {

    @Autowired
    private AutoExamService autoExamService;

    // 上传照片到oss 自动识别数据段 放入数据库
    @OperLog(operModul = "自动评卷管理-oss删除替换文件",operType = OprLogConst.DELETE,operDesc = "oss删除替换文件功能")
    @ApiOperation("自动批改")
    @PostMapping("/exam")
    public ApiResult<String> exam(MultipartFile file,String answer,@PathVariable("xuanZeNum")Double xuanZeNum,@PathVariable("panDuanNum")Double panDuanNum){
//        String a=answer.toString();
        AnswerNumValue answerNumValue = new AnswerNumValue();
        answerNumValue.setXuanzeNum(xuanZeNum);
        answerNumValue.setPanduanNum(panDuanNum);
        return ApiResultHandler.buildApiResult(200,"成功",autoExamService.exam(file,answer,answerNumValue));
    }

    @OperLog(operModul = "自动评卷管理-根据urls/ids扫描试卷",operType = OprLogConst.ADD,operDesc = "根据urls/ids扫描试卷功能")
    @ApiOperation("根据urls/ids扫描试卷")
    @PostMapping("/examByUrlAndId/{answer}/{xuanZeNum}/{panDuanNum}")
    public ApiResult<String> examByUrlAndId(@RequestBody List<DeriveExcel> deriveExcelList, @PathVariable("answer")String answer,@PathVariable("xuanZeNum")Double xuanZeNum,@PathVariable("panDuanNum")Double panDuanNum){
        AnswerNumValue answerNumValue = new AnswerNumValue();
        answerNumValue.setXuanzeNum(xuanZeNum);
        answerNumValue.setPanduanNum(panDuanNum);
        return ApiResultHandler.buildApiResult(200,"成功",autoExamService.examByUrlAndId(deriveExcelList,answer,answerNumValue));
    }
}
